package pt.elvis.revanweb.client.uiBinders;

import pt.elvis.revanweb.client.CustomEvents.AdminClickEvent;
import pt.elvis.revanweb.client.CustomEvents.AppUtils;
import pt.elvis.revanweb.client.CustomEvents.BookmarkClickEvent;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author elvis
 *
 */
public class LeftMenu extends Composite {

	private static LeftMenuUiBinder uiBinder = GWT
			.create(LeftMenuUiBinder.class);

	interface LeftMenuUiBinder extends UiBinder<Widget, LeftMenu> {
	}
	
	//Verifies if the buttons are active
	private boolean isBtnBookmarksClicked = true; //By default the bookmarksPanel is first loaded
	private boolean isBtnAdminClicked = false;

	public LeftMenu() {		
		initWidget(uiBinder.createAndBindUi(this));
		shadow.addStyleName("shadowBlue");
		btnBookmarks.addStyleName("selected");
		btnBookmarks.addStyleName("blueSelected");
	}

	
	@UiField
	Label btnBookmarks;
	
	@UiField
	Label btnAdmin;
	
	@UiField
	HTMLPanel shadow;
	
	@UiHandler("btnBookmarks")
	void handleClick_Bookmarks(ClickEvent e) {
		if (!isBtnBookmarksClicked) {
			shadow.removeStyleName("shadowOrange");
			btnAdmin.removeStyleName("selected");
			btnAdmin.removeStyleName("orangeSelected");
			
			
			btnBookmarks.addStyleName("selected");
			btnBookmarks.addStyleName("blueSelected");
			shadow.addStyleName("shadowBlue");
			
			
			isBtnBookmarksClicked = true;
			isBtnAdminClicked = false;
			AppUtils.EVENT_BUS.fireEvent(new BookmarkClickEvent());
		}
			
	}
	
	@UiHandler("btnAdmin")
	void handleClick_Admin(ClickEvent e) {
		if (!isBtnAdminClicked) {
			shadow.removeStyleName("shadowBlue");
			btnBookmarks.removeStyleName("selected");
			btnBookmarks.removeStyleName("blueSelected");
			
			btnAdmin.addStyleName("selected");
			btnAdmin.addStyleName("orangeSelected");
			shadow.addStyleName("shadowOrange");
			
			isBtnBookmarksClicked = false;
			isBtnAdminClicked = true;
			AppUtils.EVENT_BUS.fireEvent(new AdminClickEvent());
		}
	}
}
